﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ManPowerEngine
{
	public class BitmapCollider : ColliderBase
	{
		/// <summary>
		/// leftmost, rightmost, topmost, bottommost in local coordination
		/// </summary>
		private int[] mBounds = new int[4];

		/// <summary>
		/// Generate the bounds of this collider
		/// </summary>
		internal void GenerateBounds()
		{
			RendererBase renderer = mGameObject.Renderer;
			// left
			mBounds[0] = (int)(-renderer.Pivot.X);
			// right
			mBounds[1] = (int)(renderer.Width - renderer.Pivot.X);
			// top
			mBounds[2] = (int)(-renderer.Pivot.Y);
			// bottom
			mBounds[3] = (int)(renderer.Height - renderer.Pivot.Y);
		}

		/// <summary>
		/// Check if the a point is in this collider or not.
		/// </summary>
		/// <param name="point">The point that is going to check in world coordination</param>
		/// <returns>if that collider falls into current collider.</returns>
		internal bool PointCheck(Vector point)
		{
			Vector localpos = mGameObject.Transform.AbsoluteToLocalPosition(point);
			bool isIn = (localpos.X >= mBounds[0] && localpos.X <= mBounds[1] &&
				localpos.Y >= mBounds[2] && localpos.Y <= mBounds[3]);
			return isIn;
		}

		internal override bool _OnScreenCheck()
		{
			RendererBase renderer = mGameObject.Renderer;
			return RenderSystem.OnScreenCheck(mGameObject.Transform.Position - renderer.Pivot - RenderSystem.CameraPosition, renderer.Width, renderer.Height);
		}
	}
}
